home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / fsInt.h- < prev    next >
Encoding:
Text File  |  1989-06-10  |  15.2 KB  |  440 lines

  1. /*
  2.  * fsInt.h --
  3.  *
  4.  *      Internal types and definitions for the fs module.
  5.  *    This file defines handle types and some sub-structures
  6.  *    that are embedded in various types of handles.  A
  7.  *    "handle" is a data structure that corresponds one-for-one
  8.  *    with a file system object, i.e. a particular file, a device,
  9.  *    a pipe, or a pseudo-device.  A handle is not always one-for-one
  10.  *    with a file system name.  Devices can have more than one name,
  11.  *    and pseudo-devices have many handles associated with one name.
  12.  *    Each handle is identfied by a unique Fs_FileID, and has a standard
  13.  *    header for manipulation by generic routines.
  14.  *    Note: FsHandleHeader is defined in fs.h because it is
  15.  *    embedded in the Fs_Stream type which is exported.
  16.  *
  17.  * Copyright 1987 Regents of the University of California
  18.  * All rights reserved.
  19.  * Permission to use, copy, modify, and distribute this
  20.  * software and its documentation for any purpose and without
  21.  * fee is hereby granted, provided that the above copyright
  22.  * notice appear in all copies.  The University of California
  23.  * makes no representations about the suitability of this
  24.  * software for any purpose.  It is provided "as is" without
  25.  * express or implied warranty.
  26.  *
  27.  * $Header: /sprite/src/kernel/fs/RCS/fsInt.h,v 8.9 89/05/14 13:59:20 brent Exp Locker: brent $ SPRITE (Berkeley)
  28.  */
  29.  
  30. #ifndef _FSINT
  31. #define _FSINT
  32.  
  33. #include "status.h"
  34. #include "list.h"
  35. #include "timer.h"
  36. #include "stdlib.h"
  37. #include "string.h"
  38.  
  39. /*
  40.  * Stream Types:
  41.  *    FS_STREAM        Top level type for stream with offset.  Streams
  42.  *                have an ID and are in the handle table to
  43.  *                support migration and shared stream offsets.
  44.  * The remaining types are for I/O handles
  45.  *    FS_LCL_FILE_STREAM    For a regular disk file stored locally.
  46.  *    FS_RMT_FILE_STREAM    For a remote Sprite file.
  47.  *    FS_LCL_DEVICE_STREAM    For a device on this host.
  48.  *    FS_RMT_DEVICE_STREAM    For a remote device.
  49.  *    FS_LCL_PIPE_STREAM    For an anonymous pipe buffered on this host.
  50.  *    FS_RMT_PIPE_STREAM    For an anonymous pipe bufferd on a remote host.
  51.  *                This type arises from process migration.
  52.  *    FS_CONTROL_STREAM    This is the stream used by the server for
  53.  *                a pseudo device to listen for new clients.
  54.  *    FS_SERVER_STREAM    The main state for a pdev request-response
  55.  *                connection.  Refereneced by the server's stream.
  56.  *    FS_LCL_PSEUDO_STREAM    A client's handle on a request-response
  57.  *                connection to a local pdev server.
  58.  *    FS_RMT_PSEUDO_STREAM    As above, but when the pdev server is remote.
  59.  *    FS_PFS_CONTROL_STREAM    Control stream for pseudo-filesystems.
  60.  *    FS_PFS_NAMING_STREAM    The request-response stream used for naming
  61.  *                operations in a pseudo-filesystem.  This
  62.  *                I/O handle is hung off the prefix table.
  63.  *    FS_LCL_PFS_STREAM    A clients' handle on a request-response
  64.  *                connection to a local pfs server.
  65.  *    FS_RMT_PFS_STREAM    As above, but when the pfs server is remote.
  66.  *    FS_RMT_CONTROL_STREAM    Needed only during get/set I/O attributes of
  67.  *                a pseudo-device whose server is remote.
  68.  *    FS_PASSING_STREAM    Used to pass streams from a pseudo-device
  69.  *                server to its client in response to an open.
  70.  *        Internet Protocols
  71.  *    FS_RAW_IP_STREAM    Raw Internet Protocol stream.
  72.  *    FS_UDP_STREAM        UDP protocol stream.
  73.  *    FS_TCP_STREAM        TCP protocol stream.
  74.  *
  75.  * The following streams are not implemented
  76.  *    FS_RMT_NFS_STREAM    NFS access implemented in kernel.
  77.  *    FS_RMT_UNIX_STREAM    For files on the old hybrid unix/sprite server.
  78.  *    FS_LCL_NAMED_PIPE_STREAM Stream to a named pipe whose backing file
  79.  *                is on the local host.
  80.  *    FS_RMT_NAMED_PIPE_STREAM Stream to a named pipe whose backing file
  81.  *                is remote. 
  82.  */
  83. #define FS_STREAM            0
  84. #define FS_LCL_FILE_STREAM        1
  85. #define FS_RMT_FILE_STREAM        2
  86. #define FS_LCL_DEVICE_STREAM        3
  87. #define FS_RMT_DEVICE_STREAM        4
  88. #define FS_LCL_PIPE_STREAM        5
  89. #define FS_RMT_PIPE_STREAM        6
  90. #define FS_CONTROL_STREAM        7
  91. #define FS_SERVER_STREAM        8
  92. #define FS_LCL_PSEUDO_STREAM        9
  93. #define FS_RMT_PSEUDO_STREAM        10
  94. #define FS_PFS_CONTROL_STREAM        11
  95. #define FS_PFS_NAMING_STREAM        12
  96. #define FS_LCL_PFS_STREAM        13
  97. #define FS_RMT_PFS_STREAM        14
  98. #define FS_RMT_CONTROL_STREAM        15
  99. #define FS_PASSING_STREAM        16
  100. #define FS_RAW_IP_STREAM        17
  101. #define FS_UDP_STREAM            18
  102. #define FS_TCP_STREAM            19
  103.  
  104. #define FS_NUM_STREAM_TYPES        20
  105.  
  106. /*
  107.  * Two arrays are used to map between local and remote types.  This has
  108.  * to happen when shipping Fs_FileIDs between clients and servers.
  109.  */
  110. extern int fsLclToRmtType[];
  111. extern int fsRmtToLclType[];
  112. /*
  113.  * FsMapLclToRmtType(type) - Maps from a local to a remote stream type.
  114.  *    This returns -1 if the input type is out-of-range.
  115.  */
  116. #define FsMapLclToRmtType(localType) \
  117.     ( ((localType) < 0 || (localType) >= FS_NUM_STREAM_TYPES) ? -1 : \
  118.     fsLclToRmtType[localType] )
  119. /*
  120.  * FsMapRmtToLclType(type) - Maps from a remote to a local stream type.
  121.  *    This returns -1 if the input type is out-of-range.
  122.  */
  123. #define FsMapRmtToLclType(remoteType) \
  124.     ( ((remoteType) < 0 || (remoteType) >= FS_NUM_STREAM_TYPES) ? -1 : \
  125.     fsRmtToLclType[remoteType] )
  126.  
  127. /*
  128.  * The following structures are subfields of the various I/O handles.
  129.  * First we define a use count structure to handle common book keeping needs.
  130.  */
  131.  
  132. typedef struct FsUseCounts {
  133.     int        ref;        /* The number of referneces to handle */
  134.     int        write;        /* The number of writers on handle */
  135.     int        exec;        /* The number of executors of handle */
  136. } FsUseCounts;
  137.  
  138. /*
  139.  * There is a system call to lock a file.  The lock state is kept in
  140.  * the I/O handle on the I/O server so that the lock has network-wide effect.
  141.  */
  142.  
  143. typedef struct FsLockState {
  144.     int        flags;        /* Bits defined below */
  145.     List_Links    waitList;    /* List of processes to wakeup when the
  146.                  * file gets unlocked */
  147.     int        numShared;    /* Number of shared lock holders */
  148.     List_Links    ownerList;    /* List of processes responsible for locks */
  149. } FsLockState;
  150.  
  151. /*
  152.  * (The following lock bits are defined in user/fs.h)
  153.  * IOC_LOCK_EXCLUSIVE - only one process may hold an exclusive lock.
  154.  * IOC_LOCK_SHARED    - many processes may hold shared locks as long as
  155.  *    there are no exclusive locks held.  Exclusive locks have to
  156.  *    wait until all shared locks go away.
  157.  */
  158.  
  159. /*
  160.  * Files or devices with remote I/O servers need to keep some recovery
  161.  * state to handle recovery after their server reboots.
  162.  */
  163.  
  164. typedef struct FsRecoveryInfo {
  165.     Sync_Lock        lock;        /* This struct is monitored */
  166.     Sync_Condition    reopenComplete;    /* Notified when the handle has been
  167.                      * re-opened at the I/O server */
  168.     int            flags;        /* defined in fsRecovery.c */
  169.     ReturnStatus    status;        /* Recovery status */
  170.     FsUseCounts        use;        /* Client's copy of use state */
  171. } FsRecoveryInfo;
  172.  
  173.  
  174. /*
  175.  * Cache information for each file.
  176.  */
  177.  
  178. typedef struct FsCachedAttributes {
  179.     int        firstByte;    /* Cached version of desc. firstByte */
  180.     int        lastByte;    /* Cached version of desc. lastByte */
  181.     int        accessTime;    /* Cached version of access time */
  182.     int        modifyTime;    /* Cached version of modify time */
  183.     int        createTime;    /* Create time (won't change, but passed
  184.                  * to clients for use in
  185.                  * statistics-gathering) */
  186.     int        userType;    /* user advisory file type, defined in
  187.                  * user/fs.h */
  188.     /*
  189.      * The following fields are needed by Proc_Exec.
  190.      */
  191.     int        permissions;    /* File permissions */
  192.     int        uid;        /* User ID of owner */
  193.     int        gid;        /* Group Owner ID */
  194. } FsCachedAttributes;
  195.  
  196. typedef struct FsCacheFileInfo {
  197.     List_Links       links;       /* Links for the list of dirty files.
  198.                       THIS MUST BE FIRST in the struct */
  199.     List_Links       dirtyList;       /* List of dirty blocks for this file.
  200.                     * THIS MUST BE SECOND, see the macro
  201.                     * in fsBlockCache.c that depends on it. */
  202.     List_Links       blockList;      /* List of blocks for the file */
  203.     List_Links       indList;       /* List of indirect blocks for the file */
  204.     Sync_Lock       lock;       /* This is used to serialize cache access */
  205.     int           flags;       /* Flags to indicate the state of the
  206.                       file, defined in fsBlockCache.h */
  207.     int           version;       /* Used to verify validity of cached data */
  208.     struct FsHandleHeader *hdrPtr; /* Back pointer to I/O handle */
  209.     int           blocksInCache;  /* The number of blocks that this file has
  210.                       in the cache. */
  211.     int           blocksWritten;  /* The number of blocks that have been
  212.                     * written in a row without requiring a 
  213.                     * sync of the servers cache. */
  214.     int           numDirtyBlocks; /* The number of dirty blocks in the cache.*/
  215.     Sync_Condition noDirtyBlocks;  /* Notified when all write backs done. */
  216.     int           lastTimeTried;  /* Time that last tried to see if disk was
  217.                     * available for this block. */
  218.     FsCachedAttributes attr;       /* Local version of descriptor attributes. */
  219. } FsCacheFileInfo;
  220.  
  221.  
  222. /*
  223.  * The client use state needed to allow remote client access and to
  224.  * enforce network cache consistency.  A list of state for each client
  225.  * using the file is kept, including the name server itself.  This
  226.  * is used to determine what cache consistency actions to take.
  227.  * There is synchronization over this list between subsequent open
  228.  * operations and the cache consistency actions themselves.
  229.  */
  230.  
  231. typedef struct FsConsistInfo {
  232.     Sync_Lock    lock;        /* Monitor lock used to synchronize access
  233.                  * to cache consistency routines and the
  234.                  * consistency list. */
  235.     int        flags;        /* Flags defined in fsCacheConsist.c */
  236.     int        lastWriter;    /* Client id of last client to have it open
  237.                    for write caching. */
  238.     int        openTimeStamp;    /* Generated on the server when the file is
  239.                  * opened.  Checked on clients to catch races
  240.                  * between open replies and consistency
  241.                  * messages */
  242.     FsHandleHeader *hdrPtr;    /* Back pointer to handle header needed to
  243.                  * identify the file. */
  244.     List_Links    clientList;    /* List of clients of this file.  Scanned
  245.                  * to determine cachability conflicts */
  246.     List_Links    msgList;    /* List of outstanding cache
  247.                  * consistency messages. */
  248.     Sync_Condition consistDone;    /* Opens block on this condition
  249.                  * until ongoing cache consistency
  250.                  * actions have completed */
  251.     Sync_Condition repliesIn;    /* This condition is notified after
  252.                  * all the clients told to take
  253.                  * consistency actions have replied. */
  254. } FsConsistInfo;
  255.  
  256. /* 
  257.  * The I/O descriptor for remote streams.  This is all that is needed for
  258.  *    remote devices, remote pipes, and named pipes that are not cached
  259.  *    on the local machine.  This structure is also embedded into the
  260.  *    I/O descriptor for remote files.  These stream types share some
  261.  *    common remote procedure stubs, and this structure provides
  262.  *    a common interface.
  263.  *    FS_RMT_DEVICE_STREAM, FS_RMT_PIPE_STREAM, FS_RMT_NAMED_PIPE_STREAM,
  264.  *    FS_RMT_PSEUDO_STREAM, FS_RMT_PFS_STREAM
  265.  */
  266.  
  267. typedef struct FsRemoteIOHandle {
  268.     FsHandleHeader    hdr;        /* Standard handle header.  The server
  269.                      * ID field in the hdr is used to
  270.                      * forward the I/O operation. */
  271.     FsRecoveryInfo    recovery;    /* For I/O server recovery */
  272. } FsRemoteIOHandle;
  273.  
  274. extern void FsRemoteIOHandleInit();
  275.  
  276.  
  277. /*
  278.  * The current time in seconds and the element used to schedule the update to
  279.  * it.
  280.  */
  281.  
  282. extern    int            fsTimeInSeconds;
  283. extern    Timer_QueueElement    fsTimeOfDayElement;
  284.  
  285. /*
  286.  * These record the maximum transfer size supported by the RPC system.
  287.  */
  288. extern int fsMaxRpcDataSize;
  289. extern int fsMaxRpcParamSize;
  290.  
  291. /*
  292.  * Whether or not to flush the cache at regular intervals.
  293.  */
  294.  
  295. extern Boolean fsShouldSyncDisks;
  296.  
  297. /*
  298.  * TRUE once the file system has been initialized, so we
  299.  * know we can sync the disks safely.
  300.  */
  301. extern  Boolean fsInitialized;        
  302.  
  303. /*
  304.  * The directory that temporary files will live in.
  305.  */
  306. extern    int    fsTmpDirNum;
  307.  
  308. /*
  309.  * Define the types of files that we care about in the kernel, for such
  310.  * things as statistics gathering, write-through policy, etc.  There is not
  311.  * necessarily a one-to-one mapping between these and the types defined
  312.  * in user/fs.h as FS_USER_TYPE_*; for example, FS_USER_TYPE_BINARY and
  313.  * FS_USER_TYPE_OBJECT were mapped into FS_FILE_TYPE_DERIVED before they
  314.  * were separated into two categories.  It would be possible to flag other
  315.  * derived files (text formatting output, for example) to be in the DERIVED
  316.  * category as well.  
  317.  */
  318. #define FS_FILE_TYPE_TMP 0
  319. #define FS_FILE_TYPE_SWAP 1
  320. #define FS_FILE_TYPE_DERIVED 2
  321. #define FS_FILE_TYPE_BINARY 3
  322. #define FS_FILE_TYPE_OTHER 4
  323.  
  324. /*
  325.  * Whether or not to keep information about file I/O by user file type.
  326.  */
  327. extern Boolean fsKeepTypeInfo;
  328.  
  329. /*
  330.  * Fs_StringNCopy
  331.  *
  332.  *    Copy the null terminated string in srcStr to destStr and return the
  333.  *    actual length copied in *strLengthPtr.  At most numBytes will be
  334.  *    copied if the string is not null-terminated.
  335.  */
  336.  
  337. #define    Fs_StringNCopy(numBytes, srcStr, destStr, strLengthPtr) \
  338.     (Proc_IsMigratedProcess() ? \
  339.         Proc_StringNCopy(numBytes, srcStr, destStr, strLengthPtr) : \
  340.         Vm_StringNCopy(numBytes, srcStr, destStr, strLengthPtr))
  341.  
  342. /*
  343.  * Writing policies.
  344.  */
  345. extern    Boolean    fsDelayTmpFiles;
  346. extern    Boolean    fsWriteThrough;
  347. extern    Boolean    fsWriteBackASAP;
  348. extern    Boolean    fsWriteBackOnClose;
  349. extern    Boolean    fsWBOnLastDirtyBlock;
  350.  
  351.  
  352.  
  353. /*
  354.  * Wait list routines.  Waiting lists for various conditions are kept
  355.  * hanging of I/O handles.
  356.  */
  357. extern    void        FsWaitListInsert();
  358. extern    void        FsWaitListNotify();
  359. extern    void        FsFastWaitListInsert();
  360. extern    void        FsFastWaitListNotify();
  361. extern    void        FsWaitListDelete();
  362. extern    void        FsWaitListRemove();
  363.  
  364. /*
  365.  * Name lookup routines.
  366.  */
  367. extern    ReturnStatus    FsLookupOperation();
  368. extern    ReturnStatus    FsTwoNameOperation();
  369.  
  370. /*
  371.  * Cache size control.
  372.  */
  373. extern    void        FsSetMinSize();
  374. extern    void        FsSetMaxSize();
  375.  
  376. /*
  377.  * File handle routines.
  378.  */
  379. extern    void          FsHandleInit();
  380. extern    Boolean         FsHandleInstall();
  381. extern    FsHandleHeader     *FsHandleFetch();
  382. extern    FsHandleHeader    *FsHandleDup();
  383. extern  FsHandleHeader    *FsGetNextHandle();
  384. extern    void          FsHandleLockHdr();
  385. extern    void         FsHandleInvalidate();
  386. extern    Boolean        FsHandleValid();
  387. extern    void        FsHandleIncRefCount();
  388. extern    void        FsHandleDecRefCount();
  389. extern    Boolean         FsHandleUnlockHdr();
  390. extern    void          FsHandleReleaseHdr();
  391. extern    void          FsHandleRemoveHdr();
  392. extern    Boolean         FsHandleAttemptRemove();
  393. extern    void          FsHandleRemoveInt();
  394.  
  395. /*
  396.  * Macros to handle type casting when dealing with handles.
  397.  */
  398. #define FsHandleFetchType(type, fileIDPtr) \
  399.     (type *)FsHandleFetch(fileIDPtr)
  400.  
  401. #define FsHandleDupType(type, handlePtr) \
  402.     (type *)FsHandleDup((FsHandleHeader *)handlePtr)
  403.  
  404. #define FsHandleLock(handlePtr) \
  405.     FsHandleLockHdr((FsHandleHeader *)handlePtr)
  406.  
  407. #define FsHandleUnlock(handlePtr) \
  408.     (void)FsHandleUnlockHdr((FsHandleHeader *)handlePtr)
  409.  
  410. #define FsHandleRelease(handlePtr, locked) \
  411.     FsHandleReleaseHdr((FsHandleHeader *)handlePtr, locked)
  412.  
  413. #define FsHandleRemove(handlePtr) \
  414.     FsHandleRemoveHdr((FsHandleHeader *)handlePtr)
  415.  
  416. #define FsHandleName(handlePtr) \
  417.     ((((FsHandleHeader *)handlePtr)->name == (char *)NIL) ? "(no name)" : \
  418.     ((FsHandleHeader *)handlePtr)->name)
  419. /*
  420.  * Routines for use by the name component hash table.  They increment the
  421.  * low-level reference count on a handle when it is in the cache.
  422.  */
  423. extern    void         FsHandleIncRefCount();
  424. extern    void         FsHandleDecRefCount();
  425.  
  426. /*
  427.  * Miscellaneous.
  428.  */
  429. extern    void        FsFileError();
  430. extern    void        FsUpdateTimeOfDay();
  431. extern    void        FsClearStreamID();
  432. extern    void        FsAssignAttrs();
  433. extern  int         FsFindFileType();
  434. extern    char *        FsFileTypeToString();
  435. extern  void         FsRecordDeletionStats();
  436.  
  437. #define mnew(type)    (type *)malloc(sizeof(type))
  438.  
  439. #endif _FSINT
  440.